<?php
include '../main/main.inc.php';
if(!$session->sesssionExists())
	die("Sessione Inesistente");


class Signup extends signup_data 
{
	public function __construct()
	{
		parent::__construct();
		
		switch ($_POST['op'])
		{
			case "AjaxGetEventListProgrammed":
				echo $this->AjaxGetEventListProgrammed();
			break;
			case "AjaxGetPgConfirmed":
				echo $this->AjaxGetPgConfirmed();
			break;
			case "AjaxGetPgQueue":
				echo $this->AjaxGetPgQueue();
			break;
			case "AjaxGetPgOut":
				echo $this->AjaxGetPgOut();
			break;
			case "AjaxButtonQueueActive":
				echo $this->AjaxButtonQueueActive();
			break;
			case "AjaxGetSignupBox":
				echo $this->AjaxGetSignupBox();
			break;
			case "AjaxSetSignup":
				echo $this->AjaxSetSignup();
			break;
			case "AjaxSetSignupConfirmed":
				echo $this->AjaxSetSignupConfirmed();
			break;
			case "AjaxGetPgRoleOnEvent":
				echo $this->AjaxGetPgRoleOnEvent();
			break;
		}
	}
	
	public function AjaxGetEventListProgrammed()
	{
		$Event_data = parent::getEventListProgrammed();
		
		if($Event_data)
		{
			$elEventListGrid = new elSimplyGrid();
			$elEventListGrid->setDataOption('startdate','long-time');
			$elEventListGrid->setDataOption('duedate','long-time');
			$elEventListGrid->setDataOption('enddate','long-time');
			$elEventListGrid->createSimplyGrid('Lista Eventi in Programmazione', 'eventlist_p', array('Nome Evento', 'Istanza', 'Start', 'End', 'Scadenza'), 
				$Event_data,
				el::elButton('signup_event', 'Iscriviti a questo Evento')
			);	
			return $elEventListGrid->elSimplyGrid;
		}
		else
			return null;	
	}
	
	public function AjaxGetPgConfirmed()
	{
		$roledata = parent::getAllRoleClean();
		
		foreach($roledata as $rowRole)
		{
			$confirmed_data = parent::getPgConfirmed($rowRole['roleid']);
			
			$profiles = profiles::getProfilesIstance();
			
			if($profiles->permission('_user_can_allow_raid_player_out'))
			{
				$button = el::elButton('setqueue'.$rowRole['rolename'],'Togli il ruolo '.$rowRole['rolename'].' dai Confermati');
				$button .= el::elS().el::elButton('setout'.$rowRole['rolename'],'Annulla iscrizione '.$rowRole['rolename']);
			}
			
			if($confirmed_data)
			{
				$elConfirmedListGrid = new elSimplyGrid();
				$elConfirmedListGrid->setDataOption("signuptime", "long-time");
				$elConfirmedListGrid->setStaticOption('<img title="Vuole essere avvertito via Email se confermato!" src="images/email.png" />','','istrue','option_signupemail');
				$elConfirmedListGrid->setStaticOption('<img title=\"$title\" src=\"images/comment.png\" />','','istexteval','option_signupcomment');
				$elConfirmedListGrid->createSimplyGrid('Lista Ruoli '.$rowRole['rolename'].' Confermati', 'confirmedpglist'.$rowRole['rolename'], array('Nome Personaggio', 'Classe', 'Utente', 'Data Iscrizione', 'Ruolo Iscrizione'), $confirmed_data, $button, 2
					
				);	
				$rolereturn[$rowRole['rolename']] = $elConfirmedListGrid->elSimplyGrid;
			}
			else
				$rolereturn[$rowRole['rolename']] = el::elDivBox("emptyrole",'Lista Ruoli '.$rowRole['rolename'].' Confermati', "Nessuno Ruolo ".$rowRole['rolename'].' Confermato', false);		
		
				$rolereturn['role'][] = $rowRole['rolename']; 
		}
		
		return json_encode($rolereturn);
	}
	
	public function AjaxGetPgQueue()
	{
		$queue_data = parent::getPGQueue($_POST['eventid']);

		$profiles = profiles::getProfilesIstance();
		
		
		
		if($profiles->permission('_user_can_allow_raid_player_out'))
			$button .= el::elButton('setout','Annulla Questa Iscrizione').el::elS();
		else
			$button .= el::elButton('setoutyourpg','Annulla la tua iscrizione',array("disabled"=>"disabled")).el::elS();
		
		if($profiles->permission('_user_can_allow_raid_player_confirmed'))
			$button .= el::elButton('setconfirmedmain','Conferma Ruolo Iscrizione').el::elS();
		
		if($profiles->permission('_user_can_allow_raid_player_confirmed'))
			$button .= el::elButton('setconfirmedsecond','Conferma Ruolo Secondario',array("disabled"=>"disabled"));
		
		if($queue_data)
		{
			$elQueueListGrid = new elSimplyGrid();
			$elQueueListGrid->setDataOption("signuptime", "long-time");
			$elQueueListGrid->setDataOption("role","combo_list");
			$elQueueListGrid->setStaticOption('<img title="Vuole essere avvertito via Email se confermato!" src="images/email.png" />','','istrue','option_signupemail');
			$elQueueListGrid->setStaticOption('<img title=\"$title\" src=\"images/comment.png\" />','','istexteval','option_signupcomment');
			$elQueueListGrid->createSimplyGrid('Lista Gioctori In Coda', 'queuepglist', array('Nome Personaggio', 'Classe', 'Utente', 'Data Iscrizione', 'Ruolo Iscrizione', 'Ruoli Disponibili'), $queue_data, $button, 2
				
			);	
			return $elQueueListGrid->elSimplyGrid;
		}
		else
			return el::elDivBox("emptyqueue",'Lista Gioctori In Coda', 'Nessun Giocatore in Coda', false);		
	}
	
	public function AjaxGetPgOut()
	{
		$out_data = parent::getPgOut();
		
		if($out_data)
		{
			$elOutListGrid = new elSimplyGrid();
			$elOutListGrid->createSimplyGrid('Lista Giocatori non Disponibili', 'outpglist', array('Nome Personaggio', 'Utente', 'Ruolo Primario', 'Ruolo Secondario'), $out_data, $button
				
			);	
			return $elOutListGrid->elSimplyGrid;
		}
		else
			return el::elDivBox("emptyout",'Lista Giocatori non Disponibili', 'Nessuno Giocatore non disponibile', false);		
	}
	
	public function AjaxButtonQueueActive(){
		$array['buttonoutyourpg'] = parent::getIsYourPg();
		$array['pghavesecondrole'] = parent::getIsHaveSecondRole();
		return json_encode($array);
	}
	
	public function AjaxGetSignupBox()
	{
		$pg_allow = parent::getPgAllowOnEvent($_REQUEST['eventid']);
		if($pg_allow)
		{
			$profiles = profiles::getProfilesIstance();
			
			$signupstatus_data = parent::getStatusAll();


			$elform .= 	el::elSelect('Seleziona un Personaggio', 'pgid', $pg_allow)
			.el::elC()
			.el::elSelect('Seleziona il ruolo','signuprole')
			.el::elC()
			.el::elSelect('Seleziona lo stato','signupstatus',$signupstatus_data)
			.el::elC()
			.el::elCheck("Avvertimi via E-mail in caso di conferma","checkemail","1")
			.el::elC()
			.el::elTextArea('Commento Iscrizione','signupcomment',null, array("rows"=>"5","cols"=>"40"));
			$elButton .= el::elButton('signedin','Iscriviti');
			
			$form_signed_pg = new elStyleForm($_SESSION['username'].' Iscrivi uno dei tuoi Personaggi', 'signedpg', $elform, $elButton);
			
			return $form_signed_pg->elStyleForm;
		}
		else 
		{
			return el::elDivBox("signedpg","Iscrizione Personaggi","Spiacente non hai pg abilitati o liberi per registrarti a questo evento!", false);
		}

	}
	
	public function AjaxSetSignup()
	{
		echo parent::setSignup();
	}
	
	public function AjaxSetSignupConfirmed()
	{
		if($_POST['roleconfirmed'] == 'main')
			echo parent::setSignupConfirmedMainRole();
		elseif($_POST['roleconfirmed'] == 'second')
			echo parent::setSignupConfirmedSecondrole();
	}
	
	public function AjaxGetPgRoleOnEvent()
	{
		$data = parent::getPgRoleOnEvent();
		foreach($data as $val)
		{
			$option_return .= "<option value=\"{$val['roleid']}\" >{$val['rolename']}</option>";
		}
		
		return $option_return;
	}

}


if($session->sesssionExists())
	$signup = new Signup();
?>